/*
 * Copyright 2024 The Bazel Authors. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.google.idea.blaze.base.qsync;

import static com.google.common.collect.ImmutableSet.toImmutableSet;

import com.google.common.collect.ImmutableSet;
import com.intellij.openapi.extensions.ExtensionPointName;
import java.util.Set;

/**
 * Allows other plugins to tell us which annotation processors they replace.
 *
 * <p>For plugins that generate light classes that would otherwise be generated by an annotation
 * processor (java compiler plugin), this will cause the generated source files to be removed from
 * the project so that they do not conflict.
 */
public interface AnnotationProcessorOverride {

  ExtensionPointName<AnnotationProcessorOverride> EP_NAME =
      ExtensionPointName.create("com.google.idea.blaze.qsync.AnnotationProcessorOverride");

  static ImmutableSet<String> getAllAnnotationProcessorOverrides() {
    return EP_NAME.getExtensionList().stream()
        .map(AnnotationProcessorOverride::getOverriddenAnnotationProcessorsFqns)
        .flatMap(Set::stream)
        .collect(toImmutableSet());
  }

  /**
   * Returns fully qualified names of annotation processors that the plugin replaces. These are
   * typically classes that extend {@link javax.annotation.processing.AbstractProcessor}.
   *
   * <p>Note, in order for this to work as expected, code generated by the returned processors must
   * have the annotation {@link javax.annotation.processing.Generated} on the class, with a class
   * name matching one of those returned here.
   */
  ImmutableSet<String> getOverriddenAnnotationProcessorsFqns();
}
